package com.kuaiditu.assistant.module.retrofit.impl;

import com.alibaba.fastjson.JSON;
import com.kuaiditu.assistant.api.zzt_api.base.BaseZTResponse;
import com.kuaiditu.assistant.module.retrofit.ConverterAdapter;

import java.io.IOException;

/**
 * Created by Eenie on 2017/9/15.
 * Email: eeniework@gmail.com
 * Des:
 */

public class ZTConverterAdapter implements ConverterAdapter<String,BaseZTResponse> {

    @Override
    public String onConverterRequest(String request) throws IOException {
        return request;
    }

    @Override
    public String onConverterResponse(BaseZTResponse response) throws IOException {

        if (response.isStatus()) {
            return JSON.toJSONString(response);

        } else {
            throw new IOException(response.getMessage());
        }
    }

    @Override
    public BaseZTResponse strToObj(String str) {
        return JSON.parseObject(str, BaseZTResponse.class);
    }
}
